<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-31 17:46:49
 * @LastEditTime: 2019-11-28 15:58:02
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <link rel="stylesheet" type="text/css" href="../../css/local.css" />
    <link rel="stylesheet" type="text/css" href="../../font/iconfont.css" />
    <link rel="stylesheet" href="../../script/elementui/lib/theme-chalk/index.css?t=1">
    <link href="../../script/elementui/vue-element-table.css" rel="stylesheet" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script src="../../script/elementui/lib/index.js?t=1"></script>
    <script src="../../script/elementui/vue-element-bigdata-table.min.js?t=4"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <script type="text/javascript" src="../../script/JSLINQ.js"></script>
    <script type="text/javascript" src="../../script/ajaxFileUpload.js"></script>
    <style type="text/css">
        .mainForm {
            height: 60%;
            width: 99%;
            overflow-y: auto;
            display: flex;
            flex-wrap: wrap;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box" id="box">
            <van-nav-bar id="van-nav-bar" :title="titleName" left-arrow @click-left="onClickLeft">
                <div slot="right">
                </div>
            </van-nav-bar>

            <div class="mainForm">
                <van-row>
                    <van-col span="24">
                        <van-field v-model="formData.EmplName" label="生产人员" placeholder="请选择生产人员" class='label1'
                            required readonly is-link @click="openBaseScreen('生产人员')"></van-field>
                    </van-col>
                    <van-col span="24">
                        <van-field v-model="formData.XSGJ" label="小时工价" placeholder="" class='label1' required>
                        </van-field>
                    </van-col>
                    <van-col span="24">
                        <van-field v-model="formData.LabourCost" type='number' label="补偿工时" placeholder="请输入补偿工时"
                            class='label1' required @blur='getDGMoney'>
                        </van-field>
                    </van-col>
                    <van-col span="24">
                        <van-field v-model="formData.DGMoney" label="补偿金额" placeholder="" class='label1' required
                            readonly>
                        </van-field>
                    </van-col>
                    <van-col span="24">
                        <van-field v-model="formData.WorkContent" type='textarea' label="补偿内容描述" placeholder="请输入补偿内容描述"
                            class='label1' required>
                        </van-field>
                    </van-col>
                </van-row>
            </div>

            <div class="bottomSubmit"
                style="position: fixed;bottom: 0px;z-index: 1;width: 100%;padding: 5px 10px;right:0px">
                <div style="float:right;width:20%;">
                    <van-button round block type="info" native-type="submit" @click="Master(1)"
                        v-show='MasterEngineerID!=0&&MasterNum==1'>审核</van-button>
                </div>
                <div style="float:right;width:20%;">
                    <van-button round block type="info" native-type="submit" @click="Master(-1)"
                        v-show='MasterEngineerID!=0&&MasterNum==-1'>取消审核</van-button>
                </div>

                <div style="float:right;width:20%;">
                    <van-button round block type="info" native-type="submit" @click="saveRow" v-show='saveRowShow'>
                        {{saveRowNum==1?'提交':'编辑'}}</van-button>
                    </van-button>
                </div>
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            console.log(JSON.stringify(ret))
            var type = ret.value.type;
            var row = ret.value.row;

            if (type == '大工单子表人员') {
                if (!row) {
                    vm.formData.EmplID = 0;
                    vm.formData.EmplCode = '';
                    vm.formData.EmplName = '';
                    vm.formData.XSGJ = '';
                    vm.formData.LabourCost = '';
                    vm.formData.DGMoney = '';
                    return;
                }
                if (vm.formData.EmplID != row.EmplID) {
                    vm.formData.EmplID = row.EmplID;
                    vm.formData.EmplCode = row.EmplCode;
                    vm.formData.EmplName = row.EmplName;
                    let obj = {};
                    obj.EmplID = vm.formData.EmplCode
                    console.log(JSON.stringify(obj));
                    // APP.ajax('DG_GETXSDJ', obj, function (res) {
                    //     console.log(JSON.stringify(res));
                    //     if (res.ds.length) {
                    //         vm.formData.XSGJ = res.ds[0].XSDJ;
                    //     }
                    //      else {
                    //         vm.$toast("选择的生产人员没有对应的小时工价！");
                    //         vm.formData.XSGJ = '';
                    //     }
                    //     vm.formData.LabourCost = '';
                    //     vm.formData.DGMoney = '';
                    // })
                }
            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                titleName: api.pageParam.titleName,
                serverIP: APP.serverIP(),
                MasterEngineerID: 0,
                MasterNum: 1,
                saveRowShow: true,
                saveRowNum: 1,
                formData: {
                    FkeyID: api.pageParam.FkeyID || 0,
                    EmplID: 0,
                    EmplCode: '',
                    EmplName: '',
                    XSGJ: '',
                    LabourCost: '',
                    DGMoney: '',
                    WorkContent: '',
                    LabourCost1: api.pageParam.LabourCost,
                    BZZBGSL: api.pageParam.BZZBGSL,
                    SFBT: api.pageParam.SFBT,
                },
            },
            created: function () {
                var that = this;
            },
            mounted() {
                var navBar = document.getElementById('van-nav-bar')
                navBar.style.paddingTop = api.safeArea.top + 'px'
            },
            methods: {
                Master(num) {
                    var that = this;

                    that.MasterNum = num
                    var obj = {
                        Type: that.MasterNum,
                        MasterEngineerID: that.MasterEngineerID
                    }
                    console.log(JSON.stringify(obj))
                    APP.ajax('APP_DGSH', obj, function (res) {
                        console.log(JSON.stringify(res))
                        if (res.ds[0].status == 0) {
                            if (num == -1) {
                                that.saveRowShow = true
                                that.MasterNum = 1

                            } else {
                                that.MasterNum = -1
                                title = '审核'
                                if (that.saveRowShow == true) {
                                    that.saveRow()
                                }
                                api.toast({
                                    msg: '审核' + res.ds[0].msg
                                })
                            }


                        } else {
                            api.toast({
                                msg: res.ds[0].msg
                            })
                        }

                    })
                },
                getDGMoney() {
                    var that = this;
                    that.formData.DGMoney = that.formData.XSGJ * that.formData.LabourCost;
                },
                openBaseScreen(str) {
                    var that = this
                    api.openWin({
                        name: 'treeMultipleChoose',
                        url: '../tool/treeMultipleChoose.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            cmd: 'getEmplName'
                        }
                    })
                    // var that = this;
                    // let obj;
                    // if (str == '生产人员') {
                    //     obj = {
                    //         allowClear: true,
                    //         cmd: 'getEmplName',
                    //         type: str,
                    //         serverSearch: {
                    //             isPaging: false,		//是否分页
                    //             searchKey: 'EmplName',		//搜索关键词，应包含在param中
                    //             showText: 'EmplName',		//查询结果显示的字段
                    //             pageIndexStr: ''	//分页页码字段，应包含在param中
                    //         },
                    //         param: {

                    //         }

                    //     }
                    // }
                    // api.openWin({
                    //     name: str + 'baseScreen',
                    //     url: '../tool/baseScreen1.html',
                    //     reload: true,
                    //     slidBackEnabled: false,
                    //     pageParam: obj
                    // })
                },
                saveRow() {
                    var that = this;
                    if (!that.formData.EmplCode) {
                        vm.$toast("请选择生产人员！");
                        return false;
                    }
                    if (!that.formData.XSGJ) {
                        vm.$toast("选择的生产人员没有对应的小时工价！");
                        return false;
                    }
                    if (!that.formData.LabourCost) {
                        vm.$toast("请输入补偿工时！");
                        return false;
                    }
                    if (api.pageParam.WorkContent_IsRequired == 1) {
                        if (!that.formData.WorkContent) {
                            vm.$toast("请输入补偿内容！");
                            return false;
                        }
                    }

                    let obj = {};
                    obj.EmplID = that.formData.EmplCode;
                    obj.LabourCost = that.formData.LabourCost;
                    obj.FkeyID = that.formData.FkeyID;
                    obj.DGMoney = that.formData.DGMoney;
                    obj.XSGJ = that.formData.XSGJ;
                    obj.WorkContent = that.formData.WorkContent;
                    obj.LabourCost1 = that.formData.LabourCost1;
                    obj.BZZBGSL = that.formData.BZZBGSL;
                    obj.SFBT = that.formData.SFBT;
                    obj.Type = that.saveRowNum;
                    obj.MasterEngineerID1 = that.MasterEngineerID;
                    console.log(JSON.stringify(obj));
                    //alert(JSON.stringify(obj));
                    if (that.MasterEngineerID == 0) {

                        vm.$dialog.confirm({
                            title: '提示',
                            message: '是否提交该补贴单?',
                        }).then(function () {
                            APP.ajax('selectDGDByBGBT', obj, function (res) {
                                console.log(JSON.stringify(res));

                                if (res.ds[0].status == 500) {
                                    vm.$toast(res.ds[0].msg);
                                } else {
                                    vm.$dialog.alert({
                                        title: '提示',
                                        message: res.ds[0].msg,
                                    }).then(function () {
                                        // api.closeWin();
                                        if (that.saveRowNum == 1) {
                                            that.MasterEngineerID = res.ds[0].MasterEngineerID
                                        }
                                        that.saveRowShow = false
                                        that.saveRowNum = 2
                                        console.log(JSON.stringify(res.ds[0]))
                                    })
                                }
                            })

                        }).catch(function () {

                        });

                    }
                    else {
                        APP.ajax('selectDGDByBGBT', obj, function (res) {
                            console.log(JSON.stringify(res));

                            if (res.ds[0].status == 500) {
                                vm.$toast(res.ds[0].msg);
                            } else {

                                if (that.saveRowNum == 1) {
                                    that.MasterEngineerID = res.ds[0].MasterEngineerID
                                }
                                that.saveRowShow = false
                                that.saveRowNum = 2
                                console.log(JSON.stringify(res.ds[0]))

                            }
                        })

                    }


                },
                onClickLeft() {
                    api.closeWin();
                },

            }
        })
    };
</script>

</html>